package com.xuexiang.xuidemo.slice;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Component;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.Image;

import com.xuexiang.xuidemo.ResourceTable;
import com.xuexiang.xuidemo.slice.imageview.ImageLoadStrategySlice;
import com.xuexiang.xuidemo.slice.imageview.RadiusImageViewSlice;
import com.xuexiang.xuidemo.slice.imageview.edit.ImageEditSlice;
import com.xuexiang.xuidemo.slice.imageview.pictureselector.PictureSelectorSlice;
import com.xuexiang.xuidemo.slice.imageview.preview.slice.PreviewImageSlice;


/**
 * 图片
 */
public class ImageAbilitySlice extends AbilitySlice implements Component.ClickedListener {
    private Image image_back;
    private DirectionalLayout dl_radius_imageView, dl_picture_select, dl_look, dl_edit, dl_load_image;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_image);
        initView();
        initClickedListener();
    }

    public void initView() {
        image_back = (Image) findComponentById(ResourceTable.Id_image_back);
        dl_radius_imageView = (DirectionalLayout) findComponentById(ResourceTable.Id_dl_radius_imageView);
        dl_picture_select = (DirectionalLayout) findComponentById(ResourceTable.Id_dl_picture_select);
        dl_look = (DirectionalLayout) findComponentById(ResourceTable.Id_dl_look);
        dl_edit = (DirectionalLayout) findComponentById(ResourceTable.Id_dl_edit);
        dl_load_image = (DirectionalLayout) findComponentById(ResourceTable.Id_dl_load_image);
    }

    private void initClickedListener() {
        image_back.setClickedListener(this);
        dl_radius_imageView.setClickedListener(this);
        dl_picture_select.setClickedListener(this);
        dl_look.setClickedListener(this);
        dl_edit.setClickedListener(this);
        dl_load_image.setClickedListener(this);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()) {
            case ResourceTable.Id_image_back:
                Intent intent = new Intent();
                Operation operation = new Intent.OperationBuilder()
                    .withDeviceId("")
                    .withBundleName(getBundleName())
                    .withAbilityName("com.xuexiang.xuidemo.slice.MainLoadAbility")
                    .build();
                intent.setOperation(operation);
                startAbility(intent);
                setTransitionAnimation(0, 0);
                break;
            case ResourceTable.Id_dl_radius_imageView:
                present(new RadiusImageViewSlice(), new Intent());
                break;
            case ResourceTable.Id_dl_picture_select:
                present(new PictureSelectorSlice(), new Intent());
                break;
            case ResourceTable.Id_dl_look:
                present(new PreviewImageSlice(), new Intent());
                break;
            case ResourceTable.Id_dl_edit:
                present(new ImageEditSlice(), new Intent());
                break;
            case ResourceTable.Id_dl_load_image:
                present(new ImageLoadStrategySlice(), new Intent());
                break;
        }
    }

}

